﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hisun.Models;

namespace Hisun.UserControl.CostCenterItem
{
    /// <summary>
    /// 
    /// Copyright (C) 2008 HOHO``
    /// All rights reserved
    /// NameSpace:Hisun.UserControl.CostCenterItem.Search
    /// Description :
    /// Created By QiuZhongJie At 2008/10/24 12:43
    /// </summary>
    public partial class Search : System.Web.UI.UserControl
    {

        /// <summary>
        /// Gets or sets the search condition.
        /// </summary>
        /// <value>The search condition.</value>
        public string SelectedSearchCondition//搜索条件
        {
            get { return dropSearchCondition.SelectedValue; }
            set { dropSearchCondition.SelectedValue = value; }
        }

        /// <summary>
        /// Gets or sets the search word.
        /// </summary>
        /// <value>The search word.</value>
        public string SearchWord//搜索关键词
        {
            get { return txtSearchWord.Text; }
            set { txtSearchWord.Text = value; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 获得最终对于CostCenterItems表的查询Parameter
        /// </summary>
        /// <returns></returns>
        public Parameter GetParam()
        {
            try
            {
                switch (SelectedSearchCondition)
                {
                    case "作业中心ID":
                        return new Parameter("作业中心ID", TypeCode.Int32, SearchWord);
                    case "作业中心名称":
                        HisunDBDataContext db = new HisunDBDataContext();
                        int costCenterID = db.TABC_JS_CostCenter.Where(c => c.作业中心名称.Contains(SearchWord))
                            .Select(c => c.作业中心ID)
                            .Single();
                        return new Parameter("作业中心ID", TypeCode.Int32, costCenterID.ToString());

                    default:
                        return null;
                }
            }
            catch
            {
                return null;
            }
        }


        /// <summary>
        /// Adds the specified search condition.
        /// </summary>
        /// <param name="searchCondition">The search condition.</param>
        /// <param name="searchConditionValue">The search condition value.</param>
        public void Add(string searchCondition, string searchConditionValue)
        {
            dropSearchCondition.Items.Add(new ListItem(searchCondition,searchConditionValue));
        }

        /// <summary>
        /// Adds the specified search condition.
        /// </summary>
        /// <param name="searchCondition">The search condition.</param>
        public void Add(string searchCondition)
        {
            dropSearchCondition.Items.Add(new ListItem(searchCondition, searchCondition));
        }
    }
}